define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wddj/ordert/index' + location.search,
                    details_url: 'wddj/ordert/details',
                    travel_itinerary_url: 'wddj/ordert/travel_itinerary',
                    table: 'wddj_order_trailer',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'passenger.name', title: __('Passenger.name'), operate: false},
                        {field: 'passenger.mobile', title: __('Passenger.mobile'), operate: false},
                        {field: 'agent.name', title: __('Agent.name'), operate: false},
                        {field: 'agent.mobile', title: __('Agent.mobile'), operate: false},
                        {field: 'city', title: __('City'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'from_address', title: __('From_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'to_address', title: __('To_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'departure_time', title: __('Departure_time'), operate: false},
                        {field: 'driving_distance', title: __('Driving_distance'), operate:false},
                        {field: 'actual_meter', title: __('Actual_meter'), operate:false},
                        {field: 'travel_time', title: __('Travel_time'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'platform_commission', title: __('Platform_commission'), operate:'BETWEEN'},
                        {field: 'estimated_amount', title: __('Estimated_amount'), operate:'BETWEEN'},
                        {field: 'actual_amount', title: __('Actual_amount'), operate:'BETWEEN'},
                        {field: 'pay_amount', title: __('Pay_amount'), operate:'BETWEEN'},
                        {field: 'adjust_amount', title: __('Adjust_amount'), operate:'BETWEEN'},
                        {field: 'pay_method', title: __('Pay_method'), searchList: {"1":__('Pay_method 1')}, formatter: Table.api.formatter.normal, operate:false},
                        {field: 'acceptance_time', title: __('Acceptance_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'completion_time', title: __('Completion_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'state', title: __('State'), searchList: {"pending":__('State pending'),"accepted":__('State accepted'),"in_progress":__('State in_progress'),"adjusting":__('State adjusting'),"refunded":__('State refunded'),"awaiting_payment":__('State awaiting_payment'),"completed":__('State completed'),"cancelled":__('State cancelled')}, formatter: Table.api.formatter.normal},
                        {field: 'departure_images', title: __('Departure_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'arrive_images', title: __('Arrive_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                                {
                                    name: 'details',
                                    text: __('查看详情'),
                                    title: __('查看详情'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    url: 'wddj/ordert/details',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'travel_itinerary',
                                    text: __('行程路线'),
                                    title: __('行程路线'),
                                    classname: 'btn btn-xs btn-info btn-dialog bg-olive',
                                    extend: 'data-area=["100%","100%"]',
                                    url: 'wddj/ordert/travel_itinerary',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        details: function () {
            Controller.api.bindevent();
        },
        travel_itinerary: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
